package com.wmm.fast.main.shop2Observer;

import java.util.ArrayList;
import java.util.List;

/**
 * @Auther: wangzun
 * @Date: 2018/9/12 15:22
 * @Description: 通知者
 */
public abstract class Subject {
    private List<Observer> observers = new ArrayList<>();

    private String subjectState;

    //增加观察者
    public void attach(Observer observer) {
        observers.add(observer);
    }

    //减少观察者
    public void detach(Observer observer) {
        observers.remove(observer);
    }

    //通知
    public void notifys() {
        observers.forEach(observer -> {
            observer.update();
        });
    }

    public String getSubjectState() {
        return subjectState;
    }

    public void setSubjectState(String subjectState) {
        this.subjectState = subjectState;
    }
}
